using MicroMsg.Manager;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Media;
namespace MicroMsg.UI.UserContrl
{
	public class EmojProc : BaseInlineProcess
	{
		protected override int GetProbablyStartPos(string text, int startIndex)
		{
			if (string.IsNullOrEmpty(text))
			{
				return -1;
			}
			for (int i = startIndex; i < text.get_Length(); i++)
			{
				if (EmojiManager.GetInstance().getEmojiPos(text.get_Chars(i)) != -1)
				{
					return i;
				}
			}
			return -1;
		}
		protected override Inline GetCurrentElement(string text, int startIndex, ref int elementLen, ref string elementStr)
		{
			if (startIndex < 0)
			{
				return null;
			}
			int emojiPos = EmojiManager.GetInstance().getEmojiPos(text.get_Chars(startIndex));
			if (emojiPos != -1)
			{
				string text2 = text.get_Chars(startIndex).ToString();
				string emojiSrcFromFilePos = EmojiManager.GetInstance().getEmojiSrcFromFilePos(emojiPos);
				if (emojiSrcFromFilePos != null)
				{
					elementLen = text2.get_Length();
					elementStr = text2;
					InlineUIContainer inlineUIContainer = new InlineUIContainer();
					Grid grid = new Grid();
					Image image = new Image();
					grid.set_Margin(new Thickness(2.0, 0.0, 2.0, -4.0));
					image.set_Width(this.mNFontSize * 1.2);
					grid.set_Height(this.mNFontSize * 1.2 + 7.0);
					grid.set_Width(this.mNFontSize * 1.2);
					image.set_Height(this.mNFontSize * 1.2);
					image.set_VerticalAlignment(2);
					image.set_Stretch(2);
					grid.get_Children().Add(image);
					image.set_Source(new ImageSourceConverter().ConvertFromString(emojiSrcFromFilePos) as ImageSource);
					inlineUIContainer.set_Child(grid);
					return inlineUIContainer;
				}
			}
			elementLen = 0;
			elementStr = null;
			return null;
		}
	}
}
